/*
 * @lc app=leetcode id=58 lang=cpp
 *
 * [58] Length of Last Word
 */
class Solution {
public:
    int lengthOfLastWord(string s) {
        int len = s.size();
        if (len < 1) {
            return 0;
        }

        int i = len - 1;
        int ret = 0;
        bool start = true;
        while(i >= 0) {
            if (s[i] != ' ') {
                ret++;
                start=false;
            } else {
                if (!start) {
                    return ret;
                }
            }
            i--;
        }

        return start ? 0 : ret;
    }
};

